package com.zzh.takeoutapp.utils;

import com.google.gson.Gson;

/**
 * @author
 * @Name:
 * @Description: Gson封装
 * @date
 * @time
 * @copyright
 */
public class GsonResolve {

    /**
     * 将JSON字符串转换成bean
     *
     * @param jsonString 字符串
     * @param cls        实体类
     * @return
     */
    public static <T> T jsonString2Bean(String jsonString, Class<T> cls) {
        if (StringUtils.isEmpty(jsonString) == false) {
            try {
                T t = null;
                Gson gson = new Gson();// 定义实例化GSON对象
                /** 将json字符串转换成bean对象 **/
                t = gson.fromJson(jsonString, cls);
                return t;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }
}
